package de.tum.in.eist.im.client.GUIwidgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;

import de.tum.in.eist.im.client.GUI;

public class Menu extends GUIwidget {
	// Menu Bar with functions (left to right)
	private Button menuSettings;
	private Button menuLogout;

	public Menu(GUI parent) {
		setGUIandRootPanel(parent);

		menuSettings = new Button("Settings");
		menuSettings.setSize("65px", "28px");

		menuLogout = new Button("Logout");
		menuLogout.setSize("65px", "28px");

		addHandlersToWidgets();
	}

	private void addHandlersToWidgets() {
		menuSettings.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				if (menuSettings.getText().equals("Settings")) {
					parentGUI.getController().flipToSettings();
					menuSettings.setText("Chat");
				}else {
					parentGUI.getController().flipToChat();
					menuSettings.setText("Settings");
				}
			}
		});

		menuLogout.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				parentGUI.getParentIM().logout();
			}
		});
	}

	public void show() {
		rootPanel.add(menuSettings, 10, 10);
		rootPanel.add(menuLogout, 925, 10);
	}

	public void hide() {
		rootPanel.remove(menuSettings);
		rootPanel.remove(menuLogout);
	}
}
